//
//  URL.cpp
//  sad
//
//  Created by Christopher Kemsley on 2/5/12.
//  Copyright (c) 2012 iAppolopolis. All rights reserved.
//

#include <iostream>
#include "URL.hpp"

#import "XMLParser.hpp"

using namespace Sim ;








/**** URL Legacy XML Decoder (recognizes "path") ****/

struct	URLLegacyParser : public XMLParsingAgent
{
	URLLegacyParser ()
	:	XMLParsingAgent ("path") { }
	
	
	virtual XMLParser::Offset	parse	( std::string const & file , Any & outValue , XMLParser::Offset iStart )
		{
		XMLParser::Offset	pClose	=	0 ;
		XMLParser::Offset	length	=	XMLParserHelper :: findNextClose ( file , iStart , pClose ) ;
		
		// If close wasn't found
		if ( pClose == std::string::npos )
			return 0 ;
		
		outValue = URL() ;
		URL&	value	=	outValue.cast<URL> () ;
		
		value = file.substr(iStart,length) ;
		
		return iStart + length + /*"</path>"*/7 ;
		}
} ;
URLLegacyParser _URLLegacyParser ;


/**** URL XML Decoder ****/

struct	URLParser : public XMLParsingAgent
{
	URLParser ()
	:	XMLParsingAgent ("url") { }
	
	
	virtual XMLParser::Offset	parse	( std::string const & file , Any & outValue , XMLParser::Offset iStart )
		{
		XMLParser::Offset	pClose	=	0 ;
		XMLParser::Offset	length	=	XMLParserHelper :: findNextClose ( file , iStart , pClose ) ;
		
		// If close wasn't found
		if ( pClose == std::string::npos )
			return 0 ;
		
		outValue = URL() ;
		URL&	value	=	outValue.cast<URL> () ;
		
		value = file.substr(iStart,length) ;
		
		return iStart + length + /*"</url>"*/6 ;
		}
} ;
URLParser _URLParser ;



